/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.liquidByte.trafficMustang.server.webService.base;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 *
 * @author Alexandre
 */
class ErrorMessage {
    private String message;
    private String exceptionType;
    private String stackTrace;
    
    private ErrorMessage(String message, String exceptionType, String stackTrace) {
        this.message = message;
        this.exceptionType = exceptionType;
        this.stackTrace = stackTrace;
    }

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @return the exceptionType
     */
    public String getExceptionType() {
        return exceptionType;
    }

    /**
     * @return the stackTrace
     */
    public String getStackTrace() {
        return stackTrace;
    }
    
    public static ErrorMessage fromException(Exception e) {
        if (e == null) {
            return null;
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            
            return new ErrorMessage(e.getMessage(), e.getClass().getName(), sw.toString());
        }
    }
}
